package com.erp.produce.controller;

import com.erp.common.ResponseMessage;
import com.erp.produce.entity.ProductionTaskPrintingDyeing;
import com.erp.produce.service.ProductionTaskPrintingDyeingService;
import com.erp.stock.vo.ProductionTaskPrintAndDyeVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/prodPrintDye")
public class ProductionTaskPrintingDyeingController {

    @Autowired
    ProductionTaskPrintingDyeingService service;

    @ApiOperation("保存印染任务，并成品入库，当所有任务完成，改变订单状态")
    @PostMapping("/list/save1")
    public ResponseMessage saveList1(@RequestBody ProductionTaskPrintingDyeing[] list){
        Boolean success = service.saveList(list);
        if (success) {
            return ResponseMessage.ok();
        } else {
            return ResponseMessage.fail("保存失败");
        }
    }

    @ApiOperation("半成品加入印染")
    @PostMapping("/list/save")
    public ResponseMessage saveList(@RequestBody ProductionTaskPrintAndDyeVO[] list){
//        for (ProductionTaskPrintAndDyeVO vo : list) {
//            System.out.println(vo);
//        }
        Boolean success = service.savePrintingDyeingTasks(list);
        if (success) {
            return ResponseMessage.ok();
        }
        return ResponseMessage.fail("半成品加入印染失败，请重试！");
    }

    @ApiOperation("根据订单id获取对应印染任务")
    @GetMapping("list/{orderId}")
    public ResponseMessage list(@PathVariable("orderId") Long orderId){
        List<ProductionTaskPrintingDyeing> list = service.list(orderId);
        if (list.size()>0) {
            return new ResponseMessage(list);
        }
        return ResponseMessage.fail("无更多数据");
    }
}
